package cn.itlaobing.web.servlet;

import cn.itlaobing.exception.MyException;
import cn.itlaobing.model.ShoopingCarModel;
import cn.itlaobing.service.ShoopingCarService;
import cn.itlaobing.web.annotation.RequestMapping;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Created by Administrator on 2017-11-17.
 */
@WebServlet("/shopCar/*")
public class ShoopingCarServlet extends BaseServlet{
    private ShoopingCarService shoopingCarService=new ShoopingCarService();
   @RequestMapping("/skipshoopingcar")
    public void skipShoopingCar(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //只是用户在天头点击进入购物车的时候从数据库读取信息
       //不需要添加信息
       List<ShoopingCarModel> list=null;
       try {
           list=shoopingCarService.findAll();
       } catch (MyException e) {
           e.printStackTrace();
       }
       float shopTotal=0f;
       for(ShoopingCarModel sc:list){
           if(sc.getGoodCount()==null||sc.getGoodPrice()==null)
           {

               continue;
           }
           Float price=sc.getGoodPrice();
           Integer count=sc.getGoodCount();
           shopTotal+=price*count;
       }
       request.getSession().setAttribute("SHOPTOTAL_SESSION",shopTotal);
       request.getSession().setAttribute("SHOOINGCAR_SESSION",list);
       request.getRequestDispatcher("/WEB-INF/views/order/shopcar/see.jsp").forward(request,response);
    }
}
